package com.example.myvideoplayer.Utils;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.myvideoplayer.Bean.Video;
import com.example.myvideoplayer.R;

import java.util.ArrayList;

public class MyVideoAdapter extends BaseAdapter {
    private ArrayList<Video> mData;
    private Context mContext;

    public MyVideoAdapter(ArrayList<Video> mData, Context mContext) {
        this.mData = mData;
        this.mContext = mContext;
    }

    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Log.i("adapter_getview", "getView: ");
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.video, parent, false);
            holder = new ViewHolder();
            holder.tv_video_title = convertView.findViewById(R.id.tv_video_title);
//            holder.tv_music_artist = convertView.findViewById(R.id.video_artist);
            holder.tv_video_size = convertView.findViewById(R.id.tv_video_size);
            holder.tv_video_duration = convertView.findViewById(R.id.tv_video_duration);
            holder.iv_video_icon = convertView.findViewById(R.id.iv_video_icon);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.tv_video_title.setText(mData.get(position).getName());
//        holder.tv_music_artist.setText(mData.get(position).getArtist());
        holder.tv_video_size.setText(String.valueOf(mData.get(position).getSize()));
        holder.tv_video_duration.setText(Untils.formatTime(mData.get(position).getDuration()));
        holder.iv_video_icon.setImageBitmap(mData.get(position).getCover());
        return convertView;
    }

    static class ViewHolder {
        TextView tv_video_title;
//        TextView tv_music_artist;
        TextView tv_video_size;
        TextView tv_video_duration;
        ImageView iv_video_icon;
    }
}
